package com.whj.servicemap.remote;

import com.whj.internalcommon.constant.AMapConfigConstant;
import com.whj.internalcommon.dto.ResponseResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

/**
 * @Auther: wanghaijun
 * @Date: 2023/1/10 - 01 - 10 - 13:54 
 * @Description: com.whj.servicemap.remote
 */

@Service
@Slf4j
public class MapDicDistrictClient {

    @Value("${amap.key}")
    private String amapKey;

    @Autowired
    private RestTemplate restTemplate;

    /**
     * 根据传来的keywords，将得到的数据转成字符串
     * @param keywords
     * @return
     */
    public String dicDistrict(String keywords){
        StringBuilder url = new StringBuilder();
        url.append(AMapConfigConstant.DISTRICT_URL);
        url.append("?");
        url.append("keywords="+keywords);
        url.append("&");
        url.append("subdistrict=3");
        url.append("&");
        url.append("key="+amapKey);
        log.info(url.toString());

        ResponseEntity<String> forEntity = restTemplate.getForEntity(url.toString(), String.class);

        return forEntity.getBody();
    }
}
